package mo.daliy;

import java.util.ArrayDeque;
import java.util.Deque;

public class L901 {

    private Deque<int[]> queue;
    private int idx;

    public L901() {
        idx = -1;
        queue = new ArrayDeque<>();
        queue.add(new int[]{-1, Integer.MAX_VALUE});
    }

    public int next(int price) {
        idx++;
        while (queue.peek()[1] <= price) {
            queue.pop();
        }
        int ret = idx - queue.peek()[0];
        queue.push(new int[]{idx, price});
        return ret;
    }

}
